// var i;
// var $module_Fighting_UIBindings = require("./Module_Fighting_UIBindings");
// var $eventManager = require("./EventManager");
// var $evenType = require("./EvenType");
// var $excel = require("./Excel");
// var $baseModule = require("./BaseModule");
// var $gameDataManager = require("./GameDataManager");
// var $tipsManager = require("./TipsManager");
// var $bundleConfig = require("./BundleConfig");
// var $uIManager = require("./UIManager");
// var $uIConfig_Home = require("./UIConfig_Home");
// var $playerDataManager = require("./PlayerDataManager");
// var $uIRotate = require("./UIRotate");
// var $const_Hall = require("./Const_Hall");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var $logManager = require("./LogManager");
// var $uIConfig_Game = require("./UIConfig_Game");
// var $gameGlobalVariable = require("./GameGlobalVariable");
// var $aDManager = require("./ADManager");
// var $uI_BoxAward = require("./UI_BoxAward");
// var $aIControl = require("./AIControl");
// var $tTAPI = require("./TTAPI");
// var G = cc._decorator;
// var D = G.ccclass;
// var T = G.property;
// var S = G.inspector;
// var N = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.qiehuanNode = null;
//         t.boshuaward = null;
//         t.awardNode = null;
//         t.saodangLb = null;
//         t.playicon = null;
//         t.shaodanglb = null;
//         t.kaishilb = null;
//         t.zhangjieLb = null;
//         t.nowviewid = 0;
//         t.ismove = !1;
//         t.changId = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onEnable = function () {
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.Game_Value_Fei, this.onFeiQian, this);
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.Game_PASS, this.updateUi, this);
//         this.onFeiQian();
//         this.updateUi();
//         this.AICheck();
//         this.updateSaoDangUi();
//     };
//     t.prototype.updateTiLi = function () {
//         this.kaishilb.string = "×" + $gameGlobalVariable.GameGlobalVariable.kaishitilicount;
//         this.shaodanglb.string = "×" + $gameGlobalVariable.GameGlobalVariable.shaodangtilicount;
//     };
//     t.prototype.updateSaoDangUi = function () {
//         var e = $playerDataManager.PlayerDataMgr.getSaoDangCount();
//         if (e <= 0) {
//             this.playicon.active = !0;
//             this.saodangLb.node.active = !1;
//         } else {
//             this.playicon.active = !1;
//             this.saodangLb.node.active = !0;
//             this.saodangLb.string = "今日免费剩余" + e + "次";
//         }
//     };
//     t.prototype.updateUi = function () {
//         var e = $gameDataManager.GameDataMgr.getNowMaxLevel();
//         if (0 == e) {
//             this.setChangId(0);
//         } else {
//             this.setChangId(e);
//         }
//     };
//     t.prototype.onFeiQian = function () {
//         if (0 != $gameGlobalVariable.GameGlobalVariable.adddimond) {
//             $eventManager.EventMgr.dispatchEvent(
//                 $evenType.EVENT_TYPE.Home_Add_Gold,
//                 3,
//                 $gameGlobalVariable.GameGlobalVariable.adddimond
//             );
//             $gameGlobalVariable.GameGlobalVariable.adddimond = 0;
//         }
//         if (0 != $gameGlobalVariable.GameGlobalVariable.addjinbi) {
//             $eventManager.EventMgr.dispatchEvent(
//                 $evenType.EVENT_TYPE.Home_Add_Gold,
//                 2,
//                 $gameGlobalVariable.GameGlobalVariable.addjinbi
//             );
//             $gameGlobalVariable.GameGlobalVariable.addjinbi = 0;
//         }
//         if (0 != $gameGlobalVariable.GameGlobalVariable.addpower) {
//             $eventManager.EventMgr.dispatchEvent(
//                 $evenType.EVENT_TYPE.Home_Add_Gold,
//                 1,
//                 $gameGlobalVariable.GameGlobalVariable.addpower
//             );
//             $gameGlobalVariable.GameGlobalVariable.addpower = 0;
//         }
//     };
//     t.prototype.onDisable = function () {
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.Game_Value_Fei, this.onFeiQian, this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.Game_PASS, this.updateUi, this);
//     };
//     t.prototype.show = function () {
//         var e = this;
//         this.auto_ui.addClickListener(this._clickListener, this);
//         this.auto_ui.btn_sidebar.node.active = !1;
//         if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
//             mg.checkScene({
//                 scene: "sidebar",
//                 success: function (t) {
//                     e.auto_ui.btn_sidebar.node.active = t.isExist;
//                 }
//             });
//         }
//         this.auto_ui.btn_rankBtn.node.active = !1;
//         if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
//             this.auto_ui.btn_rankBtn.node.active = !0;
//         }
//     };
//     t.prototype.hide = function () {};
//     t.prototype._clickListener = function (e) {
//         var t = this;
//         var o = this.auto_ui;
//         switch (e) {
//             case o.btn_saodang:
//                 if (
//                     $playerDataManager.PlayerDataMgr.globalData.power >=
//                     $gameGlobalVariable.GameGlobalVariable.shaodangtilicount
//                 ) {
//                     $playerDataManager.PlayerDataMgr.getSaoDangCount() > 0
//                         ? ($playerDataManager.PlayerDataMgr.SubPower(
//                               $gameGlobalVariable.GameGlobalVariable.shaodangtilicount
//                           ),
//                           $playerDataManager.PlayerDataMgr.subSaoDangCount(1),
//                           this.updateSaoDangUi(),
//                           ($gameGlobalVariable.GameGlobalVariable.nowlevel = this.changId + 1),
//                           $uIManager.default.open(
//                               $bundleConfig.BundleNames.Game,
//                               $uIConfig_Game.UIView_Game.UI_GameOver,
//                               {
//                                   type: 2,
//                                   back: function () {}
//                               }
//                           ))
//                         : $aDManager.ADMgr.showRewardedVideo("视频扫荡", function () {
//                               $playerDataManager.PlayerDataMgr.SubPower(
//                                   $gameGlobalVariable.GameGlobalVariable.shaodangtilicount
//                               );
//                               $gameGlobalVariable.GameGlobalVariable.nowlevel = t.changId + 1;
//                               $uIManager.default.open(
//                                   $bundleConfig.BundleNames.Game,
//                                   $uIConfig_Game.UIView_Game.UI_GameOver,
//                                   {
//                                       type: 2,
//                                       back: function () {}
//                                   }
//                               );
//                           });
//                 } else {
//                     $tipsManager.TipMgr.showToast("体力不足");
//                 }
//                 break;
//             case o.btn_startgame:
//                 this.onClickStartGame();
//                 break;
//             case o.btn_setting:
//                 this.showSetting();
//                 break;
//             case o.btn_qiandao:
//                 this.showQianDao();
//                 break;
//             case o.btn_sidebar:
//                 $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_Sidebar);
//                 break;
//             case o.btn_rankBtn:
//                 if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
//                     $tTAPI.default.getImRankList();
//                 }
//         }
//     };
//     t.prototype.showQianDao = function () {
//         $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_QianDao);
//     };
//     t.prototype.showSetting = function () {
//         $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_Setting);
//     };
//     t.prototype.onClickStartGame = function () {
//         if (
//             $playerDataManager.PlayerDataMgr.dressUpArray.every(function (e) {
//                 return 0 != e;
//             })
//         ) {
//             var e = $excel.Excel.shuiguoguanqia(this.changId + 1);
//             var t = $gameDataManager.GameDataMgr.getNowLevelPassState(e.id, 2);
//             if (1 == t || 2 == t) {
//                 $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Hall_StartGame, this.changId + 1);
//             } else {
//                 $tipsManager.TipMgr.showToast("暂未解锁");
//             }
//         } else {
//             $tipsManager.TipMgr.showToast("背包中有空位未上阵水果");
//         }
//     };
//     t.prototype.setNowView = function (e) {
//         var t = this;
//         var o = this.qiehuanNode.children[this.nowviewid];
//         var n = null;
//         if (0 == this.nowviewid) {
//             n = this.qiehuanNode.children[1];
//         } else {
//             n = this.qiehuanNode.children[0];
//         }
//         this.ismove = !0;
//         if (1 == e) {
//             cc.tween(o)
//                 .to(0.25, {
//                     x: 375 + o.width
//                 })
//                 .start();
//             n.x = -(375 + n.width);
//             cc.tween(n)
//                 .to(0.25, {
//                     x: 0
//                 })
//                 .call(function () {
//                     t.ismove = !1;
//                 })
//                 .start();
//         } else {
//             cc.tween(o)
//                 .to(0.25, {
//                     x: -(375 + o.width)
//                 })
//                 .start();
//             n.x = 375 + n.width;
//             cc.tween(n)
//                 .to(0.25, {
//                     x: 0
//                 })
//                 .call(function () {
//                     t.ismove = !1;
//                 })
//                 .start();
//         }
//         if (0 == this.nowviewid) {
//             this.nowviewid = 1;
//         } else {
//             this.nowviewid = 0;
//         }
//         var i = $gameDataManager.GameDataMgr.getNowMaxLevel() + $gameGlobalVariable.GameGlobalVariable.houlevelunlock;
//         var a = $excel.Excel.shuiguoguanqia_all.size;
//         if (i > a) {
//             i = a;
//         }
//         this.auto_ui.node_rightNode.active = !0;
//         this.auto_ui.node_leftNode.active = !0;
//         if (this.changId + 1 > i - 1) {
//             this.auto_ui.node_rightNode.active = !1;
//         }
//         if (this.changId - 1 < 0) {
//             this.auto_ui.node_leftNode.active = !1;
//         }
//         this.updateRenData();
//     };
//     t.prototype.updateRenData = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             var t;
//             var o;
//             var n;
//             var i;
//             var a;
//             var r;
//             var c;
//             var l;
//             var u;
//             return __generator(this, function (s) {
//                 switch (s.label) {
//                     case 0:
//                         e = $excel.Excel.shuiguoguanqia(this.changId + 1);
//                         t = $gameDataManager.GameDataMgr.nowLevelData(this.changId + 1);
//                         $logManager.LogMgr.debug("当前关卡本地数据", t);
//                         o = this.qiehuanNode.children[this.nowviewid];
//                         return [
//                             4,
//                             this._loadRes(
//                                 $bundleConfig.BundleNames.Home,
//                                 "res/初始之地/levelicon" + e.dipicture,
//                                 cc.SpriteFrame
//                             )
//                         ];
//                     case 1:
//                         switch (
//                             ((n = s.sent()),
//                             (o.getComponent(cc.Sprite).spriteFrame = n),
//                             (o.children[0].getComponent(cc.Sprite).spriteFrame = n),
//                             (this.auto_ui.txt_title.string = e.id + "." + e.levelname),
//                             $gameDataManager.GameDataMgr.getNowLevelPassState(e.id, 2))
//                         ) {
//                             case -1:
//                                 this.auto_ui.btn_startgame.node.active = !1;
//                                 this.auto_ui.txt_zhangjielb.node.active = !0;
//                                 this.auto_ui.txt_zhangjielb.string = "通过第" + this.changId + "章节解锁";
//                                 this.auto_ui.txt_levelstate.string = "未解锁";
//                                 this.auto_ui.btn_saodang.node.active = !1;
//                                 o.children[0].active = !0;
//                                 break;
//                             case 1:
//                                 this.auto_ui.txt_zhangjielb.node.active = !1;
//                                 this.auto_ui.btn_startgame.node.active = !0;
//                                 this.auto_ui.txt_levelstate.string = "已通关";
//                                 this.auto_ui.btn_saodang.node.active = !0;
//                                 o.children[0].active = !1;
//                                 break;
//                             case 2:
//                                 this.auto_ui.btn_startgame.node.active = !0;
//                                 this.auto_ui.txt_zhangjielb.node.active = !1;
//                                 this.auto_ui.txt_levelstate.string =
//                                     "最高纪录:" +
//                                     $gameDataManager.GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) +
//                                     "/" +
//                                     e.levelboshuid.length;
//                                 this.auto_ui.btn_saodang.node.active = !1;
//                                 o.children[0].active = !1;
//                         }
//                         for (i = this.boshuaward.children, u = 0; u < i.length; u++) {
//                             a = i[u];
//                             r = e.awardboshuid[u];
//                             a.children[1].getComponent(cc.Label).string = "第" + r + "波";
//                             $gameDataManager.GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) >= r
//                                 ? $gameDataManager.GameDataMgr.getLevelAwardJilu(this.changId + 1, r)
//                                     ? ((a.children[0].getChildByName("unlockimg").active = !0),
//                                       (a.children[0].getChildByName("lockimg").active = !1),
//                                       (a.children[0].getChildByName("redpoint").active = !1),
//                                       a.children[0].getComponent($uIRotate.default).stopRotate())
//                                     : ((a.children[0].getChildByName("unlockimg").active = !1),
//                                       (a.children[0].getChildByName("lockimg").active = !0),
//                                       (a.children[0].getChildByName("redpoint").active = !0),
//                                       a.children[0].getComponent($uIRotate.default).startRotate())
//                                 : ((a.children[0].getChildByName("unlockimg").active = !1),
//                                   (a.children[0].getChildByName("lockimg").active = !0),
//                                   (a.children[0].getChildByName("redpoint").active = !1),
//                                   a.children[0].getComponent($uIRotate.default).stopRotate());
//                         }
//                         for (c = !1, u = this.changId; u >= 0; u--) {
//                             if ($gameDataManager.GameDataMgr.getLevelAwardHave(u)) {
//                                 c = !0;
//                             }
//                         }
//                         for (
//                             this.auto_ui.node_leftNode.getChildByName("redpoint").active = c,
//                                 l = !1,
//                                 u = this.changId + 2;
//                             u < $excel.Excel.shuiguoguanqia_all.size;
//                             u++
//                         ) {
//                             if ($gameDataManager.GameDataMgr.getLevelAwardHave(u)) {
//                                 l = !0;
//                             }
//                         }
//                         this.auto_ui.node_rightNode.getChildByName("redpoint").active = l;
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.onAwardBoxClick = function (e, t) {
//         var o = $excel.Excel.shuiguoguanqia(this.changId + 1);
//         var n = o.awardboshuid[Number(t) - 1];
//         if ($gameDataManager.GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) >= n) {
//             if ($gameDataManager.GameDataMgr.getLevelAwardJilu(this.changId + 1, n)) {
//                 $tipsManager.TipMgr.showToast("已领取");
//             } else {
//                 {
//                     $tipsManager.TipMgr.showToast("恭喜获得奖励");
//                     switch (t) {
//                         case "1":
//                             this.getAwardData(o.awardbox1);
//                             break;
//                         case "2":
//                             this.getAwardData(o.awardbox2);
//                             break;
//                         case "3":
//                             this.getAwardData(o.awardbox3);
//                     }
//                     $gameDataManager.GameDataMgr.unLevelAwardJiLu(this.changId + 1, n);
//                     this.updateRenData();
//                 }
//             }
//         } else {
//             var i = e.getCurrentTarget();
//             this.awardNode.getComponent($uI_BoxAward.default).showAward(i, o, t);
//         }
//     };
//     t.prototype.onHideAwradTip = function () {
//         if (this.awardNode.active) {
//             this.awardNode.active = !1;
//         }
//     };
//     t.prototype.getAwardData = function (e) {
//         var t = new $const_Hall.GetItemsData();
//         t.ids = [];
//         t.counts = [];
//         for (var o = 0; o < e.length; o++) {
//             var n = e[o];
//             switch (n[0]) {
//                 case 1:
//                     t.ids.push($hallGlobalVariable.default.goldId);
//                     t.counts.push(n[1]);
//                     break;
//                 case 2:
//                     t.ids.push($hallGlobalVariable.default.diamondId);
//                     t.counts.push(n[1]);
//                     break;
//                 case 3:
//                     t.ids.push($hallGlobalVariable.default.powerId);
//                     t.counts.push(n[1]);
//                     break;
//                 case 5:
//                     var i = null;
//                     if (1 == n[1]) {
//                         i = $hallGlobalVariable.default.GetSuiPian([n[2], 0, 0]);
//                     }
//                     if (2 == n[1]) {
//                         i = $hallGlobalVariable.default.GetSuiPian([0, n[2], 0]);
//                     }
//                     if (3 == n[1]) {
//                         i = $hallGlobalVariable.default.GetSuiPian([0, 0, n[2]]);
//                     }
//                     i.forEach(function (e, o) {
//                         t.ids.push(o);
//                         t.counts.push(e);
//                     });
//             }
//         }
//         t.clickCallBack = function () {
//             for (var e = 0; e < t.ids.length; e++) {
//                 var o = t.ids[e];
//                 var n = t.counts[e];
//                 switch (o) {
//                     case $hallGlobalVariable.default.goldId:
//                         $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Home_Add_Gold, 2, n);
//                         break;
//                     case $hallGlobalVariable.default.diamondId:
//                         $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Home_Add_Gold, 3, n);
//                         break;
//                     case $hallGlobalVariable.default.powerId:
//                         $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Home_Add_Gold, 1, n);
//                         break;
//                     default:
//                         $tipsManager.TipMgr.showToast("恭喜获得水果碎片");
//                         $playerDataManager.PlayerDataMgr.AddEquipFragments(o, n);
//                 }
//             }
//         };
//         $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_GetItems, t);
//     };
//     t.prototype.setChangId = function (e) {
//         this.changId = e;
//         this.auto_ui.node_rightNode.active = !0;
//         this.auto_ui.node_leftNode.active = !0;
//         this.qiehuanNode.children[this.nowviewid];
//         this.updateRenData();
//         var t = $gameDataManager.GameDataMgr.getNowMaxLevel() + $gameGlobalVariable.GameGlobalVariable.houlevelunlock;
//         var o = $excel.Excel.shuiguoguanqia_all.size;
//         if (t > o) {
//             t = o;
//         }
//         if (this.changId + 1 > t - 1) {
//             this.auto_ui.node_rightNode.active = !1;
//         }
//         if (this.changId - 1 < 0) {
//             this.auto_ui.node_leftNode.active = !1;
//         }
//     };
//     t.prototype.nextLevel = function () {
//         if (!this.ismove) {
//             this.changId += 1;
//             this.setNowView(2);
//         }
//     };
//     t.prototype.lastLevel = function () {
//         if (!this.ismove) {
//             this.changId -= 1;
//             this.setNowView(1);
//         }
//     };
//     t.prototype.AICheck = function () {
//         if ($aIControl.default._instance.isOpen) {
//             var e = this;
//             $aIControl.default._instance.ShowClickBtn(this.auto_ui.btn_startgame.node, function () {
//                 e.onClickStartGame();
//             });
//         }
//     };
//     __decorate([T($module_Fighting_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     __decorate([T(cc.Node)], t.prototype, "qiehuanNode", void 0);
//     __decorate([T(cc.Node)], t.prototype, "boshuaward", void 0);
//     __decorate([T(cc.Node)], t.prototype, "awardNode", void 0);
//     __decorate([T(cc.Label)], t.prototype, "saodangLb", void 0);
//     __decorate([T(cc.Node)], t.prototype, "playicon", void 0);
//     __decorate([T(cc.Label)], t.prototype, "shaodanglb", void 0);
//     __decorate([T(cc.Label)], t.prototype, "kaishilb", void 0);
//     __decorate([T(cc.Label)], t.prototype, "zhangjieLb", void 0);
//     return __decorate([D], t);
// })($baseModule.default);
// exports.default = N;


// import Module_Fighting_UIBindings from "./Module_Fighting_UIBindings";
// import {EventMgrInstance} from "./EventManager";
// import {EVENT_TYPE} from "./EvenType";
// import { Excel } from "./Excel";
// import BaseModule from "./BaseModule";
// import { GameDataMgr} from "./GameDataManager";
// import {TipMgrInstance} from "./TipsManager";
// import {BundleNames} from "./BundleConfig";
// import UIManager from "./UIManager";
// import {PlayerDataMgr} from "./PlayerDataManager";
// import UIRotate from "./UIRotate";
// import HallGlobalVariable from "./HallGlobalVariable";
// import {LogMgr} from "./LogManager";
// import { GameGlobalVariable } from "./GameGlobalVariable";
// import { ADMgr } from "./ADManager";
// import UI_BoxAward from "./UI_BoxAward";
// import AIControl from "./AIControl";
// import { UIView_Game } from "./UIConfig_Game";
// import { UIView_Home } from "./UIConfig_Home";
// import { GetItemsData } from "./Const_Hall";


// const { ccclass, property } = cc._decorator;

// /** 
//  * 建议类名: FightingUI
//  */
// @ccclass
// class Module_Fighting extends BaseModule {
//     @property(Module_Fighting_UIBindings)
//     auto_ui: any = null;

//     @property(cc.Node)
//     qiehuanNode: cc.Node = null;

//     @property(cc.Node)
//     boshuaward: cc.Node = null;

//     @property(cc.Node)
//     awardNode: cc.Node = null;

//     @property(cc.Label)
//     saodangLb: cc.Label = null;

//     @property(cc.Node)
//     playicon: cc.Node = null;

//     @property(cc.Label)
//     shaodanglb: cc.Label = null;

//     @property(cc.Label)
//     kaishilb: cc.Label = null;

//     @property(cc.Label)
//     zhangjieLb: cc.Label = null;

//     nowviewid: number = 0;
//     ismove: boolean = false;
//     changId: number = 0;

//     onEnable() {
//         EventMgrInstance.addEventListener(EVENT_TYPE.Game_Value_Fei, this.onFeiQian, this);
//         EventMgrInstance.addEventListener(EVENT_TYPE.Game_PASS, this.updateUi, this);
//         this.onFeiQian();
//         this.updateUi();
//         this.AICheck();
//         this.updateSaoDangUi();
//     }

//     /** 
//      * 更新体力显示
//      * 建议方法名: updateStamina
//      */
//     updateTiLi() {
//         this.kaishilb.string = "×" + GameGlobalVariable.kaishitilicount;
//         this.shaodanglb.string = "×" + GameGlobalVariable.shaodangtilicount;
//     }

//     /** 
//      * 更新扫荡UI
//      * 建议方法名: updateSweepUI
//      */
//     updateSaoDangUi() {
//         const saoDangCount = PlayerDataMgr.getSaoDangCount();
//         if (saoDangCount <= 0) {
//             this.playicon.active = true;
//             this.saodangLb.node.active = false;
//         } else {
//             this.playicon.active = false;
//             this.saodangLb.node.active = true;
//             this.saodangLb.string = "今日免费剩余" + saoDangCount + "次";
//         }
//     }

//     /** 
//      * 更新UI
//      * 建议方法名: updateUI
//      */
//     updateUi() {
//         const nowMaxLevel = GameDataMgr.getNowMaxLevel();
//         if (nowMaxLevel === 0) {
//             this.setChangId(0);
//         } else {
//             this.setChangId(nowMaxLevel);
//         }
//     }

//     /** 
//      * 处理飞钱事件
//      * 建议方法名: handleFeiQian
//      */
//     onFeiQian() {
//         if (GameGlobalVariable.adddimond !== 0) {
//             EventMgrInstance.dispatchEvent(
//                 EVENT_TYPE.Home_Add_Gold,
//                 3,
//                 GameGlobalVariable.adddimond
//             );
//             GameGlobalVariable.adddimond = 0;
//         }
//         if (GameGlobalVariable.addjinbi !== 0) {
//             EventMgrInstance.dispatchEvent(
//                 EVENT_TYPE.Home_Add_Gold,
//                 2,
//                 GameGlobalVariable.addjinbi
//             );
//             GameGlobalVariable.addjinbi = 0;
//         }
//         if (GameGlobalVariable.addpower !== 0) {
//             EventMgrInstance.dispatchEvent(
//                 EVENT_TYPE.Home_Add_Gold,
//                 1,
//                 GameGlobalVariable.addpower
//             );
//             GameGlobalVariable.addpower = 0;
//         }
//     }

//     onDisable() {
//         EventMgrInstance.rmEventListener(EVENT_TYPE.Game_Value_Fei, this.onFeiQian, this);
//         EventMgrInstance.rmEventListener(EVENT_TYPE.Game_PASS, this.updateUi, this);
//     }

//     /** 
//      * 显示UI
//      * 建议方法名: showUI
//      */
//     show() {
//         this.auto_ui.addClickListener(this._clickListener, this);
//         this.auto_ui.btn_sidebar.node.active = false;
//         if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
//             // mg.checkScene({
//             //     scene: "sidebar",
//             //     success: (result: any) => {
//             //         this.auto_ui.btn_sidebar.node.active = result.isExist;
//             //     }
//             // });
//         }
//         this.auto_ui.btn_rankBtn.node.active = false;
//         if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
//             this.auto_ui.btn_rankBtn.node.active = true;
//         }
//     }

//     hide() { }

//     /** 
//      * 点击监听器
//      * 建议方法名: clickListener
//      */
//     _clickListener(event: cc.Button) {
//         const autoUI = this.auto_ui;
//         switch (event) {
//             case autoUI.btn_saodang:
//                 if (PlayerDataMgr.globalData.power >= GameGlobalVariable.shaodangtilicount) {
//                     if (PlayerDataMgr.getSaoDangCount() > 0) {
//                         PlayerDataMgr.SubPower(GameGlobalVariable.shaodangtilicount);
//                         PlayerDataMgr.subSaoDangCount(1);
//                         this.updateSaoDangUi();
//                         GameGlobalVariable.nowlevel = this.changId + 1;
//                         UIManager.open(BundleNames.Game, UIView_Game.UI_GameOver, {
//                             type: 2,
//                             back: () => { }
//                         });
//                     } else {
//                         ADMgr.showRewardedVideo("视频扫荡", () => {
//                             PlayerDataMgr.SubPower(GameGlobalVariable.shaodangtilicount);
//                             GameGlobalVariable.nowlevel = this.changId + 1;
//                             UIManager.open(BundleNames.Game, UIView_Game.UI_GameOver, {
//                                 type: 2,
//                                 back: () => { }
//                             });
//                         });
//                     }
//                 } else {
//                     TipMgrInstance.showToast("体力不足");
//                 }
//                 break;
//             case autoUI.btn_startgame:
//                 this.onClickStartGame();
//                 break;
//             case autoUI.btn_setting:
//                 this.showSetting();
//                 break;
//             case autoUI.btn_qiandao:
//                 this.showQianDao();
//                 break;
//             case autoUI.btn_sidebar:
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_Sidebar);
//                 break;
//             case autoUI.btn_rankBtn:
//                 if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
//                     // $tTAPI.default.getImRankList();
//                 }
//                 break;
//         }
//     }

//     /** 
//      * 显示签到
//      * 建议方法名: showSignIn
//      */
//     showQianDao() {
//         UIManager.open(BundleNames.Home, UIView_Home.UI_QianDao);
//     }

//     /** 
//      * 显示设置
//      * 建议方法名: showSettings
//      */
//     showSetting() {
//         UIManager.open(BundleNames.Home, UIView_Home.UI_Setting);
//     }

//     /** 
//      * 点击开始游戏
//      * 建议方法名: onClickStartGame
//      */
//     onClickStartGame() {
//         if (PlayerDataMgr.dressUpArray.every((item: number) => item !== 0)) {
//             const levelData = Excel.shuiguoguanqia(this.changId + 1);
//             const passState = GameDataMgr.getNowLevelPassState(levelData.id, 2);
//             if (passState === 1 || passState === 2) {
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.Hall_StartGame, this.changId + 1);
//             } else {
//                 TipMgrInstance.showToast("暂未解锁");
//             }
//         } else {
//             TipMgrInstance.showToast("背包中有空位未上阵水果");
//         }
//     }

//     /** 
//      * 设置当前视图
//      * 建议方法名: setCurrentView
//      */
//     setNowView(direction: number) {
//         const currentView = this.qiehuanNode.children[this.nowviewid];
//         let nextView: cc.Node;
//         if (this.nowviewid === 0) {
//             nextView = this.qiehuanNode.children[1];
//         } else {
//             nextView = this.qiehuanNode.children[0];
//         }
//         this.ismove = true;
//         if (direction === 1) {
//             cc.tween(currentView)
//                 .to(0.25, { x: 375 + currentView.width })
//                 .start();
//             nextView.x = -(375 + nextView.width);
//             cc.tween(nextView)
//                 .to(0.25, { x: 0 })
//                 .call(() => {
//                     this.ismove = false;
//                 })
//                 .start();
//         } else {
//             cc.tween(currentView)
//                 .to(0.25, { x: -(375 + currentView.width) })
//                 .start();
//             nextView.x = 375 + nextView.width;
//             cc.tween(nextView)
//                 .to(0.25, { x: 0 })
//                 .call(() => {
//                     this.ismove = false;
//                 })
//                 .start();
//         }
//         this.nowviewid = this.nowviewid === 0 ? 1 : 0;
//         const maxLevel = GameDataMgr.getNowMaxLevel() + GameGlobalVariable.houlevelunlock;
//         const totalLevels = Excel.shuiguoguanqia_all.size;
//         const maxAvailableLevel = maxLevel > totalLevels ? totalLevels : maxLevel;
//         this.auto_ui.node_rightNode.active = this.changId + 1 <= maxAvailableLevel - 1;
//         this.auto_ui.node_leftNode.active = this.changId - 1 >= 0;
//         this.updateRenData();
//     }

//     /** 
//      * 更新人物数据
//      * 建议方法名: updateCharacterData
//      */
//     async updateRenData() {
//         const levelData = Excel.shuiguoguanqia(this.changId + 1);
//         const localLevelData = GameDataMgr.nowLevelData(this.changId + 1);
//         LogMgr.debug("当前关卡本地数据", localLevelData);
//         const currentView = this.qiehuanNode.children[this.nowviewid];
//         const spriteFrame = await this._loadRes(BundleNames.Home, "res/初始之地/levelicon" + levelData.dipicture, cc.SpriteFrame);
//         currentView.getComponent(cc.Sprite).spriteFrame = spriteFrame as cc.SpriteFrame;
//         currentView.children[0].getComponent(cc.Sprite).spriteFrame = spriteFrame as cc.SpriteFrame;
//         this.auto_ui.txt_title.string = levelData.id + "." + levelData.levelname;
//         const passState = GameDataMgr.getNowLevelPassState(levelData.id, 2);
//         switch (passState) {
//             case -1:
//                 this.auto_ui.btn_startgame.node.active = false;
//                 this.auto_ui.txt_zhangjielb.node.active = true;
//                 this.auto_ui.txt_zhangjielb.string = "通过第" + this.changId + "章节解锁";
//                 this.auto_ui.txt_levelstate.string = "未解锁";
//                 this.auto_ui.btn_saodang.node.active = false;
//                 currentView.children[0].active = true;
//                 break;
//             case 1:
//                 this.auto_ui.txt_zhangjielb.node.active = false;
//                 this.auto_ui.btn_startgame.node.active = true;
//                 this.auto_ui.txt_levelstate.string = "已通关";
//                 this.auto_ui.btn_saodang.node.active = true;
//                 currentView.children[0].active = false;
//                 break;
//             case 2:
//                 this.auto_ui.btn_startgame.node.active = true;
//                 this.auto_ui.txt_zhangjielb.node.active = false;
//                 this.auto_ui.txt_levelstate.string = "最高纪录:" + GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) + "/" + levelData.levelboshuid.length;
//                 this.auto_ui.btn_saodang.node.active = false;
//                 currentView.children[0].active = false;
//                 break;
//         }
//         const boshuAwardChildren = this.boshuaward.children;
//         for (let i = 0; i < boshuAwardChildren.length; i++) {
//             const awardNode = boshuAwardChildren[i];
//             const awardId = levelData.awardboshuid[i];
//             awardNode.children[1].getComponent(cc.Label).string = "第" + awardId + "波";
//             if (GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) >= awardId) {
//                 if (GameDataMgr.getLevelAwardJilu(this.changId + 1, awardId)) {
//                     awardNode.children[0].getChildByName("unlockimg").active = true;
//                     awardNode.children[0].getChildByName("lockimg").active = false;
//                     awardNode.children[0].getChildByName("redpoint").active = false;
//                     awardNode.children[0].getComponent(UIRotate).stopRotate();
//                 } else {
//                     awardNode.children[0].getChildByName("unlockimg").active = false;
//                     awardNode.children[0].getChildByName("lockimg").active = true;
//                     awardNode.children[0].getChildByName("redpoint").active = true;
//                     awardNode.children[0].getComponent(UIRotate).startRotate();
//                 }
//             } else {
//                 awardNode.children[0].getChildByName("unlockimg").active = false;
//                 awardNode.children[0].getChildByName("lockimg").active = true;
//                 awardNode.children[0].getChildByName("redpoint").active = false;
//                 awardNode.children[0].getComponent(UIRotate).stopRotate();
//             }
//         }
//         let leftRedPoint = false;
//         for (let i = this.changId; i >= 0; i--) {
//             if (GameDataMgr.getLevelAwardHave(i)) {
//                 leftRedPoint = true;
//             }
//         }
//         this.auto_ui.node_leftNode.getChildByName("redpoint").active = leftRedPoint;
//         let rightRedPoint = false;
//         for (let i = this.changId + 2; i < Excel.shuiguoguanqia_all.size; i++) {
//             if (GameDataMgr.getLevelAwardHave(i)) {
//                 rightRedPoint = true;
//             }
//         }
//         this.auto_ui.node_rightNode.getChildByName("redpoint").active = rightRedPoint;
//     }

//     /** 
//      * 奖励箱点击事件
//      * 建议方法名: onAwardBoxClick
//      */
//     onAwardBoxClick(event: any, customEventData: string) {
//         const levelData = Excel.shuiguoguanqia(this.changId + 1);
//         const awardId = levelData.awardboshuid[Number(customEventData) - 1];
//         if (GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) >= awardId) {
//             if (GameDataMgr.getLevelAwardJilu(this.changId + 1, awardId)) {
//                 TipMgrInstance.showToast("已领取");
//             } else {
//                 TipMgrInstance.showToast("恭喜获得奖励");
//                 switch (customEventData) {
//                     case "1":
//                         this.getAwardData(levelData.awardbox1);
//                         break;
//                     case "2":
//                         this.getAwardData(levelData.awardbox2);
//                         break;
//                     case "3":
//                         this.getAwardData(levelData.awardbox3);
//                         break;
//                 }
//                 GameDataMgr.unLevelAwardJiLu(this.changId + 1, awardId);
//                 this.updateRenData();
//             }
//         } else {
//             const targetNode = event.getCurrentTarget();
//             this.awardNode.getComponent(UI_BoxAward).showAward(targetNode, levelData, customEventData);
//         }
//     }

//     /** 
//      * 隐藏奖励提示
//      * 建议方法名: hideAwardTip
//      */
//     onHideAwradTip() {
//         if (this.awardNode.active) {
//             this.awardNode.active = false;
//         }
//     }

//     /** 
//      * 获取奖励数据
//      * 建议方法名: getAwardData
//      */
//     getAwardData(awardData: any[]) {
//         const getItemsData = new GetItemsData();
//         getItemsData.ids = [];
//         getItemsData.counts = [];
//         for (const award of awardData) {
//             switch (award[0]) {
//                 case 1:
//                     getItemsData.ids.push(HallGlobalVariable.goldId);
//                     getItemsData.counts.push(award[1]);
//                     break;
//                 case 2:
//                     getItemsData.ids.push(HallGlobalVariable.diamondId);
//                     getItemsData.counts.push(award[1]);
//                     break;
//                 case 3:
//                     getItemsData.ids.push(HallGlobalVariable.powerId);
//                     getItemsData.counts.push(award[1]);
//                     break;
//                 case 5:
//                     let fragments = null;
//                     if (award[1] === 1) {
//                         fragments = HallGlobalVariable.GetSuiPian([award[2], 0, 0]);
//                     } else if (award[1] === 2) {
//                         fragments = HallGlobalVariable.GetSuiPian([0, award[2], 0]);
//                     } else if (award[1] === 3) {
//                         fragments = HallGlobalVariable.GetSuiPian([0, 0, award[2]]);
//                     }
//                     fragments.forEach((count, id) => {
//                         getItemsData.ids.push(id);
//                         getItemsData.counts.push(count);
//                     });
//                     break;
//             }
//         }
//         getItemsData.clickCallBack = () => {
//             for (let i = 0; i < getItemsData.ids.length; i++) {
//                 const id = getItemsData.ids[i];
//                 const count = getItemsData.counts[i];
//                 switch (id) {
//                     case HallGlobalVariable.goldId:
//                         EventMgrInstance.dispatchEvent(EVENT_TYPE.Home_Add_Gold, 2, count);
//                         break;
//                     case HallGlobalVariable.diamondId:
//                         EventMgrInstance.dispatchEvent(EVENT_TYPE.Home_Add_Gold, 3, count);
//                         break;
//                     case HallGlobalVariable.powerId:
//                         EventMgrInstance.dispatchEvent(EVENT_TYPE.Home_Add_Gold, 1, count);
//                         break;
//                     default:
//                         TipMgrInstance.showToast("恭喜获得水果碎片");
//                         PlayerDataMgr.AddEquipFragments(id, count);
//                 }
//             }
//         };
//         UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
//     }

//     /** 
//      * 设置章节ID
//      * 建议方法名: setChapterId
//      */
//     setChangId(chapterId: number) {
//         this.changId = chapterId;
//         this.auto_ui.node_rightNode.active = true;
//         this.auto_ui.node_leftNode.active = true;
//         this.qiehuanNode.children[this.nowviewid];
//         this.updateRenData();
//         const maxLevel = GameDataMgr.getNowMaxLevel() + GameGlobalVariable.houlevelunlock;
//         const totalLevels = Excel.shuiguoguanqia_all.size;
//         const maxAvailableLevel = maxLevel > totalLevels ? totalLevels : maxLevel;
//         this.auto_ui.node_rightNode.active = this.changId + 1 <= maxAvailableLevel - 1;
//         this.auto_ui.node_leftNode.active = this.changId - 1 >= 0;
//     }

//     /** 
//      * 下一关
//      * 建议方法名: nextLevel
//      */
//     nextLevel() {
//         if (!this.ismove) {
//             this.changId += 1;
//             this.setNowView(2);
//         }
//     }

//     /** 
//      * 上一关
//      * 建议方法名: previousLevel
//      */
//     lastLevel() {
//         if (!this.ismove) {
//             this.changId -= 1;
//             this.setNowView(1);
//         }
//     }

//     /** 
//      * AI检查
//      * 建议方法名: checkAI
//      */
//     AICheck() {
//         if (AIControl._instance.isOpen) {
//             AIControl._instance.ShowClickBtn(this.auto_ui.btn_startgame.node, () => {
//                 this.onClickStartGame();
//             });
//         }
//     }

//     /** 
//      * 加载资源
//      * 建议方法名: loadResource
//      */
//     protected async _loadRes(bundleName: string, path: string, type: typeof cc.Asset): Promise<cc.Asset> {
//         return new Promise((resolve, reject) => {
//             cc.assetManager.loadBundle(bundleName, (err, bundle) => {
//                 if (err) {
//                     reject(err);
//                     return;
//                 }
//                 bundle.load(path, type, (err, asset) => {
//                     if (err) {
//                         reject(err);
//                         return;
//                     }
//                     resolve(asset);
//                 });
//             });
//         });
//     }
// }

// export default Module_Fighting;


import ModuleFightingUIBindings from "./Module_Fighting_UIBindings";
import { EventMgrInstance } from "./EventManager";
import { EVENT_TYPE } from "./EvenType";
import { Excel } from "./Excel";
import BaseModule from "./BaseModule";
import { GameDataMgr } from "./GameDataManager";
import { TipMgr } from "./TipsManager";
import { BundleNames } from "./BundleConfig";
import UIManager from "./UIManager";
import { PlayerDataMgr } from "./PlayerDataManager";
import UIRotate from "./UIRotate";
import FruitDataManager from "./HallGlobalVariable";
import { LogMgr } from "./LogManager";
import { GameGlobalVariable } from "./GameGlobalVariable";
import { ADMgr } from "./ADManager";
import ViewBoxAward from "./UI_BoxAward";
import AICtrl from "./AIControl";
import { UIView_Game } from "./UIConfig_Game";
import { UIView_Home } from "./UIConfig_Home";
import { GetItemsData } from "./Const_Hall";

const { ccclass, property } = cc._decorator;

/**
 * 建议类名: FightingUI
 */
@ccclass
class ModuleFighting extends BaseModule {
    @property(ModuleFightingUIBindings)
    auto_ui: any = null;

    @property(cc.Node)
    qiehuanNode: cc.Node = null;

    @property(cc.Node)
    boshuaward: cc.Node = null;

    @property(cc.Node)
    awardNode: cc.Node = null;

    @property(cc.Label)
    saodangLb: cc.Label = null;

    @property(cc.Node)
    playicon: cc.Node = null;

    @property(cc.Label)
    shaodanglb: cc.Label = null;

    @property(cc.Label)
    kaishilb: cc.Label = null;

    @property(cc.Label)
    zhangjieLb: cc.Label = null;

    nowviewid: number = 0;
    ismove: boolean = false;
    changId: number = 0;

    onEnable() {
        EventMgrInstance.addListener(EVENT_TYPE.Game_Value_Fei, this.handleFeiQian, this);
        EventMgrInstance.addListener(EVENT_TYPE.Game_PASS, this.updateUI, this);
        this.handleFeiQian();
        this.updateUI();
        this.checkAI();
        this.updateSweepUI();
    }

    /**
     * 更新体力显示
     * 建议方法名: updateStamina
     */
    updateStamina() {
        this.kaishilb.string = "×" + GameGlobalVariable.kaishitilicount;
        this.shaodanglb.string = "×" + GameGlobalVariable.shaodangtilicount;
    }

    /**
     * 更新扫荡UI
     * 建议方法名: updateSweepUI
     */
    updateSweepUI() {
        const saoDangCount = PlayerDataMgr.getSaoDangCount();
        if (saoDangCount <= 0) {
            this.playicon.active = true;
            this.saodangLb.node.active = false;
        } else {
            this.playicon.active = false;
            this.saodangLb.node.active = true;
            this.saodangLb.string = "今日免费剩余" + saoDangCount + "次";
        }
    }

    /**
     * 更新UI
     * 建议方法名: updateUI
     */
    updateUI() {
        const nowMaxLevel = GameDataMgr.getCurrentMaxLevel();
        this.setChapterId(nowMaxLevel === 0 ? 0 : nowMaxLevel);
    }

    /**
     * 处理飞钱事件
     * 建议方法名: handleFeiQian
     */
    handleFeiQian() {
        const { adddimond, addjinbi, addpower } = GameGlobalVariable;
        if (adddimond !== 0) {
            EventMgrInstance.emitEvent(EVENT_TYPE.Home_Add_Gold, 3, adddimond);
            GameGlobalVariable.adddimond = 0;
        }
        if (addjinbi !== 0) {
            EventMgrInstance.emitEvent(EVENT_TYPE.Home_Add_Gold, 2, addjinbi);
            GameGlobalVariable.addjinbi = 0;
        }
        if (addpower !== 0) {
            EventMgrInstance.emitEvent(EVENT_TYPE.Home_Add_Gold, 1, addpower);
            GameGlobalVariable.addpower = 0;
        }
    }

    onDisable() {
        EventMgrInstance.removeListener(EVENT_TYPE.Game_Value_Fei, this.handleFeiQian, this);
        EventMgrInstance.removeListener(EVENT_TYPE.Game_PASS, this.updateUI, this);
    }

    /**
     * 显示UI
     * 建议方法名: showUI
     */
    show() {
        this.auto_ui.addClickListener(this._clickListener, this);
        const { btn_sidebar, btn_rankBtn } = this.auto_ui;
        btn_sidebar.node.active = false;
        if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
            // mg.checkScene({
            //     scene: "sidebar",
            //     success: (result: any) => {
            //         btn_sidebar.node.active = result.isExist;
            //     }
            // });
        }
        btn_rankBtn.node.active = cc.sys.platform === cc.sys.BYTEDANCE_GAME;
    }

    hide() {}

    /**
     * 点击监听器
     * 建议方法名: clickListener
     */
    _clickListener(event: cc.Button) {
        const autoUI = this.auto_ui;
        switch (event) {
            case autoUI.btn_saodang:
                this._handleSweepClick();
                break;
            case autoUI.btn_startgame:
                this.onClickStartGame();
                break;
            case autoUI.btn_setting:
                this.showSettings();
                break;
            case autoUI.btn_qiandao:
                this.showSignIn();
                break;
            case autoUI.btn_sidebar:
                UIManager.open(BundleNames.Home, UIView_Home.UI_Sidebar);
                break;
            case autoUI.btn_rankBtn:
                if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
                    // $tTAPI.default.getImRankList();
                }
                break;
        }
    }

    _handleSweepClick() {
        if (PlayerDataMgr.globalData.power >= GameGlobalVariable.shaodangtilicount) {
            if (PlayerDataMgr.getSaoDangCount() > 0) {
                this._consumeSweepResources();
            } else {
                ADMgr.showRewardedVideoAd("视频扫荡", this._consumeSweepResources.bind(this));
            }
        } else {
            TipMgr.showToast("体力不足");
        }
    }

    _consumeSweepResources() {
        PlayerDataMgr.subtractPower(GameGlobalVariable.shaodangtilicount);
        PlayerDataMgr.subSaoDangCount(1);
        this.updateSweepUI();
        GameGlobalVariable.nowlevel = this.changId + 1;
        UIManager.open(BundleNames.Game, UIView_Game.UI_GameOver, {
            type: 2,
            back: () => {}
        });
    }

    /**
     * 显示签到
     * 建议方法名: showSignIn
     */
    showSignIn() {
        UIManager.open(BundleNames.Home, UIView_Home.UI_QianDao);
    }

    /**
     * 显示设置
     * 建议方法名: showSettings
     */
    showSettings() {
        UIManager.open(BundleNames.Home, UIView_Home.UI_Setting);
    }

    /**
     * 点击开始游戏
     * 建议方法名: onClickStartGame
     */
    onClickStartGame() {
        if (PlayerDataMgr.dressUpArray.every((item: number) => item !== 0)) {
            const levelData = Excel.shuiguoguanqia(this.changId + 1);
            const passState = GameDataMgr.getCurrentLevelPassState(levelData.id, 2);
            if (passState === 1 || passState === 2) {
                EventMgrInstance.emitEvent(EVENT_TYPE.Hall_StartGame, this.changId + 1);
            } else {
                TipMgr.showToast("暂未解锁");
            }
        } else {
            TipMgr.showToast("背包中有空位未上阵水果");
        }
    }

    /**
     * 设置当前视图
     * 建议方法名: setCurrentView
     */
    setCurrentView(direction: number) {
        const currentView = this.qiehuanNode.children[this.nowviewid];
        const nextView = this.qiehuanNode.children[this.nowviewid === 0 ? 1 : 0];
        this.ismove = true;

        const moveOutX = direction === 1 ? 375 + currentView.width : -(375 + currentView.width);
        const moveInX = direction === 1 ? -(375 + nextView.width) : 375 + nextView.width;

        cc.tween(currentView)
            .to(0.25, { x: moveOutX })
            .start();

        nextView.x = moveInX;
        cc.tween(nextView)
            .to(0.25, { x: 0 })
            .call(() => {
                this.ismove = false;
            })
            .start();

        this.nowviewid = this.nowviewid === 0 ? 1 : 0;
        this._updateRightLeftNode();
        this.updateCharacterData();
    }

    _updateRightLeftNode() {
        const maxLevel = GameDataMgr.getCurrentMaxLevel() + GameGlobalVariable.houlevelunlock;
        const totalLevels = Excel.shuiguoguanqia_all.size;
        const maxAvailableLevel = Math.min(maxLevel, totalLevels - 1);
        this.auto_ui.node_rightNode.active = this.changId + 1 <= maxAvailableLevel;
        this.auto_ui.node_leftNode.active = this.changId - 1 >= 0;
    }

    /**
     * 更新人物数据
     * 建议方法名: updateCharacterData
     */
    async updateCharacterData() {
        const levelData = Excel.shuiguoguanqia(this.changId + 1);
        const localLevelData = GameDataMgr.getCurrentLevelData(this.changId + 1);
        LogMgr.debug("当前关卡本地数据", localLevelData);

        const currentView = this.qiehuanNode.children[this.nowviewid];
        const spriteFrame = await this._loadRes(BundleNames.Home, `res/初始之地/levelicon${levelData.dipicture}`, cc.SpriteFrame);
        
        currentView.getComponent(cc.Sprite).spriteFrame = spriteFrame as cc.SpriteFrame;
        currentView.children[0].getComponent(cc.Sprite).spriteFrame = spriteFrame as cc.SpriteFrame;
        
        this._updateUIElements(levelData);
    }
    
    _updateUIElements(levelData: any) {
        this.auto_ui.txt_title.string = `${levelData.id}.${levelData.levelname}`;
        const passState = GameDataMgr.getCurrentLevelPassState(levelData.id, 2);

        switch (passState) {
            case -1:
                this._handleLockedLevel();
                break;
            case 1:
                this._handleCompletedLevel();
                break;
            case 2:
                this._handleCurrentLevel(levelData);
                break;
        }

        this._updateBoshuAwards(levelData);
    }

    _handleLockedLevel() {
        this.auto_ui.btn_startgame.node.active = false;
        this.auto_ui.txt_zhangjielb.node.active = true;
        this.auto_ui.txt_zhangjielb.string = `通过第${this.changId}章节解锁`;
        this.auto_ui.txt_levelstate.string = "未解锁";
        this.auto_ui.btn_saodang.node.active = false;
        this.qiehuanNode.children[this.nowviewid].children[0].active = true;
    }

    _handleCompletedLevel() {
        this.auto_ui.txt_zhangjielb.node.active = false;
        this.auto_ui.btn_startgame.node.active = true;
        this.auto_ui.txt_levelstate.string = "已通关";
        this.auto_ui.btn_saodang.node.active = true;
        this.qiehuanNode.children[this.nowviewid].children[0].active = false;
    }

    _handleCurrentLevel(levelData: any) {
        this.auto_ui.btn_startgame.node.active = true;
        this.auto_ui.txt_zhangjielb.node.active = false;
        this.auto_ui.txt_levelstate.string = `最高纪录:${GameDataMgr.getMaxLevelWaveState(this.changId + 1, 2)}/${levelData.levelboshuid.length}`;
        this.auto_ui.btn_saodang.node.active = false;
        this.qiehuanNode.children[this.nowviewid].children[0].active = false;
    }

    _updateBoshuAwards(levelData: any) {
        const boshuAwardChildren = this.boshuaward.children;
        for (let i = 0; i < boshuAwardChildren.length; i++) {
            const awardNode = boshuAwardChildren[i];
            const awardId = levelData.awardboshuid[i];
            
            awardNode.children[1].getComponent(cc.Label).string = `第${awardId}波`;
            this._updateBoshuAwardNode(awardNode, awardId);
        }
        this._updateRedPoints();
    }

    _updateBoshuAwardNode(awardNode: cc.Node, awardId: number) {
        const isUnlocked = GameDataMgr.getMaxLevelWaveState(this.changId + 1, 2) >= awardId;
        const hasAward = isUnlocked && GameDataMgr.getLevelAwardRecord(this.changId + 1, awardId);

        const unlockImg = awardNode.children[0].getChildByName("unlockimg");
        const lockImg = awardNode.children[0].getChildByName("lockimg");
        const redPoint = awardNode.children[0].getChildByName("redpoint");
        const rotateCmp = awardNode.children[0].getComponent(UIRotate);

        unlockImg.active = hasAward;
        lockImg.active = !hasAward;
        redPoint.active = !hasAward && isUnlocked;
        
        hasAward ? rotateCmp.stopRotateTween() : rotateCmp.startRotateTween();
    }

    _updateRedPoints() {
        this.auto_ui.node_leftNode.getChildByName("redpoint").active = this._hasLeftRedPoint();
        this.auto_ui.node_rightNode.getChildByName("redpoint").active = this._hasRightRedPoint();
    }

    _hasLeftRedPoint() {
        for (let i = this.changId; i >= 0; i--) {
            if (GameDataMgr.hasLevelAward(i)) return true;
        }
        return false;
    }

    _hasRightRedPoint() {
        for (let i = this.changId + 2; i < Excel.shuiguoguanqia_all.size; i++) {
            if (GameDataMgr.hasLevelAward(i)) return true;
        }
        return false;
    }

    /**
     * 奖励箱点击事件
     * 建议方法名: onAwardBoxClick
     */
    onAwardBoxClick(event: any, customEventData: string) {
        const levelData = Excel.shuiguoguanqia(this.changId + 1);
        const awardId = levelData.awardboshuid[Number(customEventData) - 1];
        if (GameDataMgr.getMaxLevelWaveState(this.changId + 1, 2) >= awardId) {
            if (GameDataMgr.getLevelAwardRecord(this.changId + 1, awardId)) {
                TipMgr.showToast("已领取");
            } else {
                this._handleAwardAcquisition(customEventData, levelData);
                GameDataMgr.updateLevelAwardRecord(this.changId + 1, awardId);
                this.updateCharacterData();
            }
        } else {
            this._displayAwardNode(event, levelData, customEventData);
        }
    }
    
    _handleAwardAcquisition(customEventData: string, levelData: any) {
        TipMgr.showToast("恭喜获得奖励");
        switch (customEventData) {
            case "1":
                this.getAwardData(levelData.awardbox1);
                break;
            case "2":
                this.getAwardData(levelData.awardbox2);
                break;
            case "3":
                this.getAwardData(levelData.awardbox3);
                break;
        }
    }

    _displayAwardNode(event: any, levelData: any, customEventData: string) {
        const targetNode = event.getCurrentTarget();
        this.awardNode.getComponent(ViewBoxAward).displayAward(targetNode, levelData, customEventData);
    }

    /**
     * 隐藏奖励提示
     * 建议方法名: hideAwardTip
     */
    onHideAwradTip() {
        if (this.awardNode.active) {
            this.awardNode.active = false;
        }
    }

    /**
     * 获取奖励数据
     * 建议方法名: getAwardData
     */
    getAwardData(awardData: any[]) {
        const getItemsData = new GetItemsData();
        getItemsData.ids = [];
        getItemsData.counts = [];
        
        for (const award of awardData) {
            this._handleAwardDistribution(award, getItemsData);
        }
        
        getItemsData.clickCallBack = this._getAwardsCallback.bind(this, getItemsData);
        
        UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
    }
    
    _handleAwardDistribution(award: any[], getItemsData: GetItemsData) {
        const [type, count, additionalData] = award;
        switch (type) {
            case 1:
                getItemsData.ids.push(FruitDataManager.goldId);
                getItemsData.counts.push(count);
                break;
            case 2:
                getItemsData.ids.push(FruitDataManager.diamondId);
                getItemsData.counts.push(count);
                break;
            case 3:
                getItemsData.ids.push(FruitDataManager.powerId);
                getItemsData.counts.push(count);
                break;
            case 5:
                this._distributeFragments(count, additionalData, getItemsData);
                break;
        }
    }
    
    _distributeFragments(count: number, additionalData: any, getItemsData: GetItemsData) {
        let fragments = null;
        if (count === 1) {
            fragments = FruitDataManager.getSuiPian([additionalData, 0, 0]);
        } else if (count === 2) {
            fragments = FruitDataManager.getSuiPian([0, additionalData, 0]);
        } else if (count === 3) {
            fragments = FruitDataManager.getSuiPian([0, 0, additionalData]);
        }
        
        fragments.forEach((fragmentCount: number, id: number) => {
            getItemsData.ids.push(id);
            getItemsData.            // fragments.forEach(... continued)
            counts.push(fragmentCount);
        });
    }

    _getAwardsCallback(getItemsData: GetItemsData) {
        getItemsData.ids.forEach((id, index) => {
            const count = getItemsData.counts[index];
            switch (id) {
                case FruitDataManager.goldId:
                    EventMgrInstance.emitEvent(EVENT_TYPE.Home_Add_Gold, 2, count);
                    break;
                case FruitDataManager.diamondId:
                    EventMgrInstance.emitEvent(EVENT_TYPE.Home_Add_Gold, 3, count);
                    break;
                case FruitDataManager.powerId:
                    EventMgrInstance.emitEvent(EVENT_TYPE.Home_Add_Gold, 1, count);
                    break;
                default:
                    TipMgr.showToast("恭喜获得水果碎片");
                    PlayerDataMgr.addEquipFragments(id, count);
            }
        });
    }

    /**
     * 设置章节ID
     * 建议方法名: setChapterId
     */
    setChapterId(chapterId: number) {
        this.changId = chapterId;
        this.auto_ui.node_rightNode.active = true;
        this.auto_ui.node_leftNode.active = true;
        this.updateCharacterData();
        this._updateRightLeftNode();
    }

    /**
     * 下一关
     * 建议方法名: nextLevel
     */
    nextLevel() {
        if (!this.ismove) {
            this.changId += 1;
            this.setCurrentView(2);
        }
    }

    /**
     * 上一关
     * 建议方法名: previousLevel
     */
    lastLevel() {
        if (!this.ismove) {
            this.changId -= 1;
            this.setCurrentView(1);
        }
    }

    /**
     * AI检查
     * 建议方法名: checkAI
     */
    checkAI() {
        if (AICtrl._instance.isOpen) {
            AICtrl._instance.displayClickButton(this.auto_ui.btn_startgame.node, () => {
                this.onClickStartGame();
            });
        }
    }

    /**
     * 加载资源
     * 建议方法名: loadResource
     */
    protected async _loadRes(bundleName: string, path: string, type: typeof cc.Asset): Promise<cc.Asset> {
        return new Promise((resolve, reject) => {
            cc.assetManager.loadBundle(bundleName, (err, bundle) => {
                if (err) {
                    reject(err);
                    return;
                }
                bundle.load(path, type, (err, asset) => {
                    if (err) {
                        reject(err);
                        return;
                    }
                    resolve(asset);
                });
            });
        });
    }
}

export default ModuleFighting;
